package Dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Dao.Daocommtype;
import entity.Commtype;
import utils.BaseDao;

public class Daoimplcommtype extends BaseDao implements Daocommtype {

	@Override
	public List<Commtype> sel() {
		String sql = "select * from commtype";
		ResultSet set = super.executeQuery(sql, null);
		List<Commtype> list = new ArrayList<Commtype>();
		try {
			while(set.next()){
				Commtype comm = new Commtype();
				comm.setId(set.getInt(1));
				comm.setName(set.getString(2));
				list.add(comm);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				super.closeAll(set, set.getStatement(), set.getStatement().getConnection());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return list;
	}

	@Override
	public boolean upd(Commtype c) {
		String sql = "update `xiangmu`.`commtype` set `name` = ? where `id` = ?";
		Object[] object = {c.getName(),c.getId()};
		return super.executeUpdate(sql, object);
	}

	@Override
	public boolean add(Commtype c) {
		String sql = "insert into commtype value(null,?)";
		Object[] object = {c.getName()};
		return super.executeUpdate(sql, object);
	}

	@Override
	public boolean del(Commtype c) {
		String sql = "delete from `xiangmu`.`commtype` where `id` = ?; ";
		Object[] object = {c.getId()};
		return super.executeUpdate(sql, object);
	}

}
